package Classes.GameRecords// ActionScript file
{
	import Classes.Interfaces.I_SendTarget;
	import Classes.Managers.M_Communication;

	/**
	 *游戏记录类
	 * 记录玩家一系列操作的消息包 
	 * @author 葛增文
	 * 
	 */	
	public class GameRecord implements I_SendTarget
	{
		private var _msgsAry:Array;
		private var _callBack:Function;/*操作完成后的回调方法*/
		public function GameRecord():void
		{
			this.init();
		}
		
		private function init():void
		{
			this._msgsAry=new Array;
		}
		
		/**
		 *增加一条记录消息 
		 * @param msgType
		 * @param msgContent
		 * 
		 */		
		public function addMsg(msgType:int,msgContent:Object=null):void
		{
			this.msgsAry.push({msgType:msgType,msgContent:msgContent});
		}
		
		/**
		 *发送记录消息 
		 * 
		 */		
		public function send(callBack:Function=null):void
		{
			this._callBack=callBack;
			if(this.msgsAry.length)
			{
				var msgContent:Object={recordsAry:this.msgsAry};
			    M_Communication.instance.send(13000,msgContent,this);
			}
			else
			{
				this.reset();
			}
		}
		
		/**
		 *恢复所有操作 
		 * @param callBack
		 * 
		 */		
		public function recoverAll(callBack:Function=null):void
		{
			this._callBack=callBack;
			this.recoverRecord();
			this.reset();
		}
		
		/**
		 *处理消息返回 
		 * @param msgObj
		 * 
		 */		
		public function dealMsg(msgObj:Object):void
		{
			if(msgObj.value)
			{
				this.finishRecord(msgObj);
			}
			else
			{
				this.recoverRecord();
			}
			this.reset();
		}
		
		/**
		 *完成记录的操作 
		 * 
		 */		
		protected function finishRecord(msgObj:Object):void
		{
			
		}
		
		/**
		 *恢复记录的操作 
		 * 
		 */		
		protected function recoverRecord():void
		{
			
		}
		
		public function reset():void
		{
			this._msgsAry=new Array;
			if(this.callBack!=null)(this.callBack)();
			this._callBack=null;
		}

		/*getter & setter*/
		public function get msgsAry():Array
		{
			return _msgsAry;
		}

		public function get callBack():Function
		{
			return _callBack;
		}


	}
}